<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Gallery
 *
 * @author Administrator
 */
class Gallery
{

    //put your code here
    private $Id;
    private $gallery_type_id;
    private $title;
    private $description;
    private $width;
    private $height;
    private $image_file;
    private $date_add;
    private $status;
    private $order;
    private $link;
    private $GTITLE;
    public function getGTITLE()
    {
	return $this->GTITLE;
    }

    public function setGTITLE($GTITLE)
    {
	$this->GTITLE = $GTITLE;
    }

    
    public function getId()
    {
        return $this->Id;
    }

    public function setId($Id)
    {
        $this->Id = $Id;
    }

    public function getGallery_type_id()
    {
        return $this->gallery_type_id;
    }

    public function setGallery_type_id($gallery_type_id)
    {
        $this->gallery_type_id = $gallery_type_id;
    }

    public function getTitle()
    {
        return $this->title;
    }

    public function setTitle($title)
    {
        $this->title = $title;
    }

    public function getDescription()
    {
        return $this->description;
    }

    public function setDescription($description)
    {
        $this->description = $description;
    }

    public function getWidth()
    {
        return $this->width;
    }

    public function setWidth($width)
    {
        $this->width = $width;
    }

    public function getHeight()
    {
        return $this->height;
    }

    public function setHeight($height)
    {
        $this->height = $height;
    }

    public function getImage_file()
    {
        return $this->image_file;
    }

    public function setImage_file($image_file)
    {
        $this->image_file = $image_file;
    }

    public function getDate_add()
    {
        return $this->date_add;
    }

    public function setDate_add($date_add)
    {
        $this->date_add = $date_add;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function setStatus($status)
    {
        $this->status = $status;
    }

    public function getOrder()
    {
        return $this->order;
    }

    public function setOrder($order)
    {
        $this->order = $order;
    }

    public function getLink()
    {
        return $this->link;
    }

    public function setLink($link)
    {
        $this->link = $link;
    }

    //ham goi img co link
    public function getImg_Link($db = null)
    {
        if ($db != null)
        {
            try
            {

                $sqlQuery = "CALL proc_getImgLink(:title);";

                $parameters = array(":title");

                $values = array($this->getTitle());

                $types = array(PDO::PARAM_STR);

                $rs_row = $db->executeQueryXtemplate($sqlQuery, $parameters, $values, $types);

                $row = array();

                while ($rows = $rs_row->fetch())
                {
                    $row[] = $rows;
                }
                return $row;
            } catch (PDOException $exc)
            {
                echo 'Lỗi: ';
                echo $exc->getMessage();
            }
        } else
        {
            echo "<script>alert('Không thấy đối tượng db vui lòng thêm lại')";
        }
    }

    //ham lay những gallery nào actived
    public function getTitle_G_Active($db = null)
    {
        if ($db != null)
        {
            try
            {

                $sqlQuery = "SELECT `group_gallery`.`title` FROM `group_gallery` 
                                WHERE `group_gallery`.`status` = TRUE; ";
                $row = array();
                $rs_row = $db->executeQuery($sqlQuery, null, null, null);
                while ($rows = $rs_row->fetch())
                {
                    $row[] = $rows;
                }
                return $row;
            } catch (PDOException $exc)
            {
                echo 'Lỗi: ';
                echo $exc->getMessage();
            }
        } else
        {
            echo "<script>alert('Không thấy đối tượng db vui lòng thêm lại')";
        }
    }

    // tải danh sách ảnh thuộc 1 nhóm gallery (get by gallery ID)
    public function getListOfImageByGalleryID($db = null)
    {
        if ($db != null)
        {
            $sqlQuery = "SELECT `Id` , `gallery_type_id` , `title` , `description` , `width` , `height` , `image_file` , `date_add` , `status` , `order` 
                            FROM `gallery`
                            WHERE gallery_type_id = :gallery_type_id";

            $parameters = array(":gallery_type_id");

            $values = array($this->getGallery_type_id());

            $types = array(PDO::PARAM_INT);

            $result = $db->executeQuery($sqlQuery, $parameters, $values, $types);

            $rows = array();

            if ($result != null)
            {
                while ($row = $result->fetch())
                {
                    $rows[] = $row;
                }
            }
            return $rows;
            
        } else
        {
            echo 'db null at function getListOfImageByGalleryID';
        }
    }
    
    public function getListGalleryByName($db = null)
    {
	if ($db != null)
        {
            $sqlQuery = "SELECT
			gallery.Id,
			gallery.gallery_type_id,
			gallery.title AS GTitle,
			gallery.description,
			gallery.width,
			gallery.link,
			gallery.height,
			gallery.image_file,
			gallery.date_add,
			group_gallery.`status`,
			gallery.`status`,
			group_gallery.title AS GG_Title
			FROM
			group_gallery
			INNER JOIN gallery ON gallery.gallery_type_id = group_gallery.Id
			WHERE gallery.`status` = 1 
			AND group_gallery.`status` = 1 AND group_gallery.title = :GGTILE;";

            $parameters = array(":GGTILE");

            $values = array($this->getGTITLE());

            $types = array(PDO::PARAM_STR);

            $result = $db->executeQuery($sqlQuery, $parameters, $values, $types);

            $rows = array();

            if ($result != null)
            {
                while ($row = $result->fetch())
                {
                    $rows[] = $row;
                }
            }
            return $rows;
            
        } else
        {
            echo 'db null at function getListOfImageByGalleryID';
        }
    }
}

?>
